#include <iostream>
#include <fstream>
#include <ctime>

using namespace std;

void bubbleSort(int list[], int listLength) {
    while(listLength--)  {
        bool swapped = false;
        
        for(int i = 0; i < listLength; i++) {
            if(list[i] > list[i + 1]){
                swap(list[i], list[i + 1]);
                swapped = true;
            }
        } 
        
        if(!swapped) break;
    }
}

void readFromFile(const char *filename, int a[], int length) {
    ifstream file(filename);

    for(int i = 0; i < length; i++)
        file >> a[i];
}

void measureTime(const char *filename, int a[], int length) {
    readFromFile(filename, a, length);
    unsigned int t_start =  clock();
    bubbleSort(a, length);
    unsigned int t_finish = clock();
    unsigned int t_work = t_finish - t_start;
    cout << filename << " " << t_work << " milliseconds \n";
}

int main()
{
    int a[5000];

    measureTime("m1_sorted.txt", a, 5000);
    measureTime("m2_reverse.txt", a, 5000);
    measureTime("m3_shuffle.txt", a, 5000);
    
    return 0;
}